import {WeaForm} from 'comsMobx'
import {observable, action, toJS} from 'mobx';
import {WeaLocaleProvider} from "ecCom";
import { Modal,message} from 'antd';
import * as conLockApi from '../apis/contractLockSend';

const getLabel = WeaLocaleProvider.getLabel;
class MainParame {
    @observable showkey = 0;
    @observable selectedKey = 0;
    //搜索的参数
    @observable parame = {};

    /**
     * 顶部的top页
     * @type {Array}
     */
    toptab = [];//顶部的tabs页
    /**
     * 收藏
     * @type {boolean}
     */
    @observable visiblecollect = false;
	
	/**
	*	权限
	*/
	@observable hasRight = false;
    
	/**
     * 弹框
     * @type {boolean}
     */
    @observable visibledialog = false;
    //新建或者编辑的参数
    @observable paramsform = {formtype: null, id: null};
    /**
     * 一键初始化
     * @type {boolean}
     */
    @observable visibledInitialization = false;
    /**
     * 高级搜索框的显示隐藏
     * @type {boolean}
     */
    @observable showSearchAd = false;

    @action setSelectedKey = value => {this.selectedKey = value;}

    @action initTopTab = () => {
        let _this = this;
        conLockApi && conLockApi.init({}).then(result => {
            if(result.status == 1) {
                _this.toptab = result.toptabs;
				_this.hasRight = result.hasRight;
                _this.setSelectedKey(result.selectKey);
            } else {
                Modal.warning({
                    title: getLabel(15172, "系统提示"),
                    content: getLabel(	500472, "请求异常！"),
                });
            }
        })
    }

    getTitleMsg(){//获取抬头的title
        if( !this.selectedKey || this.toptab.length < 1) {
            return "";//无数据
        }
        if (this.toptab[this.selectedKey] && this.toptab[this.selectedKey].title) {
            return this.toptab[this.selectedKey].title
        }
    }

    getCreateUrl = () => {//获取创建的url
        if( !this.selectedKey || this.toptab.length < 1) {
            return "";//无数据
        }

        if (this.toptab[this.selectedKey] && this.toptab[this.selectedKey].createurl) {
            return this.toptab[this.selectedKey].createurl
        }
    }
    //契约锁相关配置的执行功能
    @observable toDoParams = [];//存储参数
    @action
    setToDoParams = (params)=>{//设置参数
        this.toDoParams = params;
    }
    @observable running = false;
    @action
    immediatelyRun=(key)=>{//提交执行
        let len = toJS(this.toDoParams).length;
        if(key){
            this.confirmToRun(key);
        }else if(len>0){
            let params = toJS(this.toDoParams).join(",");
            this.confirmToRun(params);
        }else {
            message.warning(getLabel(510219,'请选择执行任务'));
        }
    }
    //确认是否执行
    confirmToRun(params){
        var _that = this;
        Modal.confirm({
            title: getLabel(22180,'计划任务执行'),
            content: getLabel(510224,'确认是否执行'),
            onOk() {
                _that.running = true;
                conLockApi.immediatelyRun({id:params}).then((result)=>{
                    _that.running = false;
                    if(result.code=="0"){
                        message.success(getLabel(506358,'执行成功'));
                    }else {
                        message.error(getLabel(83071,'执行失败'));
                    }
                });
            },
            onCancel() {},
        });
    }

    @action setVisiblecollect =() => this.visiblecollect = !this.visiblecollect;

    @action setVisibleDialog = () => this.visibledialog = !this.visibledialog;

    @action setParamsForm = (param=null) => {this.paramsform = param};

    @action setShowInitialization = (ok = false) => {this.visibledInitialization= ok};

    @action setShowSearcheAd = (bool=!this.showSearchAd) => {this.showSearchAd = bool};

    @action getShowkey() {return this.showkey}
    @action getSelectedKey ()  {return this.selectedKey}

    @action getparam() {return this.parame}

    @action setShowkey =value => {this.showkey  = value;}
    @action setParame = (parame={}) => {this.parame = parame};

}
export {MainParame}